<template>
  <div>
    <el-dialog title="修改价格" :visible="dialogVisible" :close-on-click-modal="false" @close="close" width="500px">

      <el-form :model="ruleForm" ref="ruleForm" label-width="100px" :rules="rules">

        <el-form-item label="商品编号:" prop="no">
          <span>{{orderInfo.id}}</span>
        </el-form-item>
        <el-form-item label="游戏账号:" prop="accountNumber">
          <span>{{orderInfo.accountNumber}}</span>
        </el-form-item>
        <el-form-item label="价格:" prop="">
          <span>¥{{orderInfo.price}}</span>
        </el-form-item>
        <el-form-item label="修改价格:" prop="price">
          <el-input v-model="ruleForm.price" type="text" placeholder="请输入价格"></el-input>
        </el-form-item>
      </el-form>
      <div class="center">
        <el-button @click="close('ruleForm')">关闭</el-button>
        <el-button type="primary" @click="submitForm('ruleForm')" :loading="loading">确认</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import goodsListApi from "../../../api/gameConfig/goodsList";
export default {
  name: "",
  data() {
    var priceRule = (rule, value, callback) => {
      if (value === "") {
        callback();
      } else {
        if (!this.priceReg.test(value)) {
          callback(new Error("请输入正确的价格"));
        }
        callback();
      }
    };
    return {
      dialogVisible: false,
      loading: false,
      ruleForm: {
        id: "",
        price: "",
      },
      orderInfo: {},
      rules: {
        backAmount: [
          {
            required: true,
            message: "请输入回收金额",
            trigger: "blur",
          },
          { validator: priceRule, trigger: "blur" },
        ],
        price: [
          {
            required: true,
            message: "请输入价格",
            trigger: "blur",
          },
          { validator: priceRule, trigger: "blur" },
        ],
      },
      userType: "",
    };
  },
  created() {},
  methods: {
    open(order, userType) {
      // this.userType = userType
      this.loading = false;
      this.orderInfo = order;
      this.ruleForm.id = order.id;
      this.ruleForm.price = "";
      this.dialogVisible = true;
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$confirm(
            `改价会同步推送到api接口对接的其他平台，频繁改价可能会造成其他平台价格不同步，是否继续？`,
            "提示",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "",
              dangerouslyUseHTMLString: true,
            }
          )
            .then(() => {
              this.loading = true;
              goodsListApi.goodsgaijia(this.ruleForm).then((res) => {
                this.dialogVisible = false;
                this.$parent.getList();
              });
            })
            .catch(() => {});
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    close(formName) {
      this.dialogVisible = false;
    },
  },
};
</script>
<style scoped lang="scss">
.center {
  margin-top: 30px;
}
::v-deep .el-form-item {
  margin-bottom: 5px;
}
</style>
